﻿using NUnit.Framework;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;

namespace Gadgeteer.Interfaces.Fakes.Tests
{
    [TestFixture]
    public class FakeButtonTest
    {
        [Test]
        public void Press_ForAWhile()
        {
            using (var button1 = new FakeButton())
            {
                var pressedFound = false;
                var releasedFound = false;

                button1.ButtonPressed += (s, e) =>
                {
                    pressedFound = true;
                };
                button1.ButtonReleased += (s, e) =>
                {
                    releasedFound = true;
                };

                button1.Press(new TimeSpan(0, 0, 0, 0, 400));
                Thread.Sleep(100);
                Assert.That(button1.IsPressed, Is.True, "Button should be in pressed state");
                Assert.That(pressedFound);
                Assert.That(releasedFound, Is.False);

                Thread.Sleep(350);
                
                Assert.That(pressedFound);
                Assert.That(releasedFound);
            }
        }

        [Test]
        public void Press()
        {
            using (var button1 = new FakeButton())
            {
                var pressedFound = false;
                var releasedFound = false;

                button1.ButtonPressed += (s, e) =>
                {
                    pressedFound = true;
                };
                button1.ButtonReleased += (s, e) =>
                {
                    releasedFound = true;
                };

                button1.Press();
                Thread.Sleep(100);

                Assert.That(pressedFound);
                Assert.That(releasedFound);
            }
        }
    }
}
